package com.atguigu.exam;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

/**
 * @author xbd
 * @create 2021-05-28 10:52
 */
public class CompareTest {
    public static void main(String[] args) {
        Comparator com = new Comparator(){

            @Override
            public int compare(Object o1, Object o2) {
                if(o1 instanceof String && o2 instanceof String) {
                    String s1 = (String) o1;
                    String s2 = (String) o2;
                    return -s1.compareTo(s2);
                }else{
                    throw new RuntimeException("输入数据类型不匹配！");
                }
            }
        };

        TreeSet tree = new TreeSet(com);

        tree.add("acbd");
        tree.add("bcbd");
        tree.add("dfga");
        tree.add("eesf");

        Iterator iterator = tree.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}
